class Solution {
public:
    int maxProfit(vector<int>& p)
    {
        int sum = 0;

        for (int i = 0, Min = INT_MAX; i < p.size(); i++)
        {
            sum = max(sum, p[i] - Min);
            Min = fmin(Min, p[i]);
        }
        return sum;
    }
};